package cn.codeforfun.cart;

import cn.codeforfun.common.SessionParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2016/12/18 0018.
 */
@Controller
@RequestMapping("/cart")
public class CartController {
    @RequestMapping("/getCart")
    @ResponseBody
    public Cart getCart(HttpSession session) {
        Object cart = session.getAttribute(SessionParam.CART);
        Cart newCart;
        if (cart == null) {
            newCart = new Cart();
            session.setAttribute(SessionParam.CART, newCart);
        } else {
            newCart = (Cart) cart;
        }
        return newCart;
    }
}
